// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

// 云函数入口函数
const db=cloud.database();
exports.main = async (event, context) => {
 
 try {
      let result=await cloud.openapi.security.msgSecCheck({
        content:event.loveValue
    })
    if(result.errCode==0){
      let Dates=new Date();
      let day=Dates.getDate() < 10 ? '0'+(Dates.getDate()) : Dates.getDate();
      let month=Dates.getMonth()+1 < 10 ? '0'+(Dates.getMonth()+1) : Dates.getMonth()+1;
      let year=Dates.getFullYear();
      let pushTime=year+"年"+month+"月"+day;
      let timeStamp=new Date().getTime();
  return await db.collection("loveWall").add({
    data:{
      userHead:event.userHead,
      userName:event.userName,
      userOpenid:event.userOpenid,
      loveValue:event.loveValue,
      pushTime:pushTime,
      timeStamp
    }
    })
    }
} catch (error) {
  console.log(console.error)
}
}